var js_data = require('../../data/activity/activityForIndex.js')
var activityListJs = js_data.data
var participateInJs = js_data.participateIn
const app = getApp()
Page({
  data:{
    functionList:[
      {
        "title":"一键报警",
        "name":"icon-baojingjingbao-"
      },
      {
        "title":"信息更改",
        "name":"icon-gerenxinxi1",  
        "url":'info'
      },
      {
        "title":"社区互助",
        "name":"icon-aixin",
        "url":'help'
      },
     
      {
        "title":"夕阳论坛",
        "name":"icon-luntan"
      },
    ],
    movable_x: null,
    movable_y: null,
    activitiesList:[],
    elderlyInfo:null
  },
  setMovableViewPosition: function(){
    // 获取屏幕宽高，设置悬浮新建按钮的初始位置
    var windowWidth = wx.getSystemInfoSync().windowWidth
    var windowHeight = wx.getSystemInfoSync().windowHeight
    // console.log(windowHeight)
    var movable_x = String(windowWidth / 2 - 20) + 'px'
    var movable_y = String(windowHeight - 50) + 'px'
    // x="140px" y="450px"
    this.setData({
      movable_x: movable_x,
      movable_y: movable_y
    })
  },
  onLoad:function(){
    // 读取屏幕宽高,动态调整悬浮按钮的位置
    // this.setMovableViewPosition()

    // app.sendGetRequest('/heart/list',(res) => {
    //   console.log(res)
    //   this.setData({
    //     activitiesList:res.rows
    //   })
    // })
    this._onLoad()
  },
  _onLoad(){
    this.setMovableViewPosition()
    app.sendGetRequest('/heart/wxlist',(res) => {
      console.log(res)
      this.setData({
        activitiesList:res.rows
      })
      
    })
    app.sendGetRequest('/community/elderly/byUserId', (res)=>{
      console.log(res)
      if(res.code == 200){
        this.setData({
          elderlyInfo: res.rows[0]
        })
      }
    }, (res)=>{
      console.log(res)
    },)
  },
  onPullDownRefresh(){
    this._onLoad()
    wx.stopPullDownRefresh()
  },
  gotoActivity:function(e){
    var activityId = e.currentTarget.dataset.activity_id
    wx.navigateTo({
      url: './activityDetail/activityDetail?activityId='+activityId,
    })
  },
  gotoActivityList0(){
    wx.navigateTo({
      url: './help/help?activityType=3',
    })
  },
  gotoActivityList1(){
    wx.navigateTo({
      url: './help/help?activityType=4',
    })
  },
  calling(){
    var phone = this.data.elderlyInfo.familyphone
    wx.makePhoneCall({
      phoneNumber: phone,

    })
  },
  gotoInfo(){
    wx.navigateTo({
      url: '/pages/elderly/info/info',
    })
  },
  gotoActivityListByInitiator(){
    var user_info = wx.getStorageSync('user_info')
    var user_id = user_info.user_id;
    var text = './help/help?initiatorId='+user_id
    wx.navigateTo({
      url: './help/help?activityType=-1' ,
    })
  },
  gotoMyPartActivityList(){
    wx.navigateTo({
      url: './partActivity/partActivity',
    })
  },
  createActivity: function (e){
    wx.showActionSheet({
      itemList: ['儿童发布', '夕阳论坛', '家属求助', '社区关爱'],
      success: function(res) {
          // console.log(res.tapIndex)
          var category = String(res.tapIndex+1)
          wx.navigateTo({
            url: './createActivity/createActivity?activityType=' + category,
          })
      },
      fail: function(res) {
          console.log(res.errMsg)
      }
    })
  }
  
}
)
